CREATE OR REPLACE TABLE "TBL_ENDERECO"  ( "COD_ENDERECO" NUMBER(8,0) NOT NULL ENABLE,  "RUA" VARCHAR2(40),
			 "NUMERO" NUMBER(6,0),  "BAIRRO" VARCHAR2(30),  "CIDADE" VARCHAR2(30),  "CEP" VARCHAR2(8),  "UF" VARCHAR2(2),  "TELEFONE" VARCHAR2(20),
			 CONSTRAINT "TBL_ENDERECO_PK" PRIMARY KEY ("COD_ENDERECO") ENABLE )

CREATE OR REPLACE TABLE "TBL_AUTOR"  ( "COD_AUTOR" NUMBER(8,0),
	   	  		  					   "COD_ENDERECO" NUMBER(8,0),
									   "IDENTIDADE" VARCHAR2(15),  
									   "NOME" VARCHAR2(40),  
									   CONSTRAINT "TBL_AUTOR_PK" PRIMARY KEY ("COD_AUTOR") ENABLE,
		     CONSTRAINT "TBL_AUTOR_FK" FOREIGN KEY ("COD_ENDERECO") REFERENCES "TBL_ENDERECO" ("COD_ENDERECO") ENABLE )
			 
			 
CREATE OR REPLACE  TABLE "TBL_EDITORA"  ( "COD_EDITORA" NUMBER(8,0),
	   	  		   		 				  "COD_ENDERECO" NUMBER(8,0),
										  "NOME" VARCHAR2(40),
             CONSTRAINT "TBL_EDITORA_PK" PRIMARY KEY ("COD_EDITORA") ENABLE,
			 CONSTRAINT "TBL_EDITORA_FK" FOREIGN KEY ("COD_ENDERECO") REFERENCES "TBL_ENDERECO" ("COD_ENDERECO") ENABLE )
					 
CREATE OR REPLACE  TABLE "TBL_GRAFICA"  ( "COD_GRAFICA" NUMBER(8,0),  "COD_ENDERECO" NUMBER(8,0),  "TIPO" CHAR(1),  "NOME" VARCHAR2(40),
			 "PRODUCAO_MAXIMA" NUMBER(10,0),  "RESPONSAVEL" VARCHAR2(40),  
			 CONSTRAINT "TBL_GRAFICA_PK" PRIMARY KEY ("COD_GRAFICA") ENABLE,  CONSTRAINT "TBL_GRAFICA_FK" FOREIGN KEY ("COD_ENDERECO") REFERENCES
			 "TBL_ENDERECO" ("COD_ENDERECO") ENABLE )

CREATE OR REPLACE  TABLE "TBL_LIVRO"  ( "ISBN" VARCHAR2(20),  "COD_EDITORA" NUMBER(8,0),  "TITULO" VARCHAR2(50),  "DT_PUBLICACAO" DATE,  
   	   		 CONSTRAINT "TBL_LIVRO_PK" PRIMARY KEY ("ISBN") ENABLE,  CONSTRAINT "TBL_LIVRO_FK" FOREIGN KEY ("COD_EDITORA") REFERENCES "TBL_EDITORA"
			 ("COD_EDITORA") ENABLE )
			 
CREATE TABLE "TBL_LIVRO_AUTOR"  ( "ISBN" VARCHAR2(20),  "COD_AUTOR" NUMBER(8,0)),  CONSTRAINT "TBL_LIVRO_AUTOR_PK" PRIMARY KEY ("ISBN", "COD_AUTOR")
	   		  ENABLE,  CONSTRAINT "TBL_LIVRO_AUTOR_FK" FOREIGN KEY ("ISBN") REFERENCES "TBL_LIVRO" ("ISBN") ENABLE,  
			  CONSTRAINT "TBL_LIVRO_AUTOR_FK2" FOREIGN KEY ("COD_AUTOR") REFERENCES "TBL_AUTOR" ("COD_AUTOR") ENABLE )
			  
CREATE TABLE "TBL_PEDIDO"  ( "COD_PEDIDO" NUMBER(8,0),  "COD_GRAFICA" NUMBER(8,0),  "ISBN" VARCHAR2(20),  "DT_PEDIDO" DATE,  "QTDE_COPIAS" NUMBER(8,0),
	   		 "VALOR" NUMBER(14,2),  "DT_ENTREGA" DATE,  "SITUACAO" CHAR(1)) , CONSTRAINT "TBL_PEDIDO_PK" PRIMARY KEY ("COD_PEDIDO") ENABLE,  
			 CONSTRAINT "TBL_PEDIDO_FK" FOREIGN KEY ("COD_GRAFICA") REFERENCES "TBL_GRAFICA" ("COD_GRAFICA") ENABLE,  CONSTRAINT "TBL_PEDIDO_FK2"
			 FOREIGN KEY ("ISBN") REFERENCES "TBL_LIVRO" ("ISBN") ENABLE )
			 
CREATE OR REPLACE UNIQUE INDEX "TBL_PEDIDO_PK" ON "TBL_PEDIDO" ("COD_PEDIDO")

CREATE OR REPLACE UNIQUE INDEX "TBL_LIVRO_PK" ON "TBL_LIVRO" ("ISBN")

CREATE OR REPLACE UNIQUE INDEX "TBL_LIVRO_AUTOR_PK" ON "TBL_LIVRO_AUTOR" ("ISBN", "COD_AUTOR")

CREATE OR REPLACE UNIQUE INDEX "TBL_GRAFICA_PK" ON "TBL_GRAFICA" ("COD_GRAFICA")

CREATE OR REPLACE UNIQUE INDEX "TBL_ENDERECO_PK" ON "TBL_ENDERECO" ("COD_ENDERECO")

CREATE OR REPLACE UNIQUE INDEX "TBL_EDITORA_PK" ON "TBL_EDITORA" ("COD_EDITORA")

CREATE OR REPLACE UNIQUE INDEX "TBL_AUTOR_PK" ON "TBL_AUTOR" ("COD_AUTOR")

CREATE OR REPLACE SEQUENCE "TBL_PEDIDO_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE

CREATE OR REPLACE SEQUENCE "TBL_GRAFICA_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE

CREATE OR REPLACE SEQUENCE "TBL_ENDERECO_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE

CREATE OR REPLACE SEQUENCE "TBL_EDITORA_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE

CREATE OR REPLACE SEQUENCE "TBL_AUTOR_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE

CREATE OR REPLACE TRIGGER "BI_TBL_PEDIDO"  before insert on "TBL_PEDIDO"  for each row  begin  select "TBL_PEDIDO_SEQ".nextval into :NEW.COD_PEDIDO from dual;

                           end;
						   
ALTER TRIGGER "BI_TBL_PEDIDO" ENABLE

CREATE OR REPLACE TRIGGER "BI_TBL_GRAFICA"  before insert on "TBL_GRAFICA"  for each row  begin  select "TBL_GRAFICA_SEQ".nextval into :NEW.COD_GRAFICA from dual;
                           end;
						   
ALTER TRIGGER "BI_TBL_GRAFICA" ENABLE

CREATE OR REPLACE TRIGGER "BI_TBL_ENDERECO"  before insert on "TBL_ENDERECO"  for each row  begin  select "TBL_ENDERECO_SEQ".nextval into :NEW.COD_ENDERECO from dual;
 	   	  		  		    end;
							
ALTER TRIGGER "BI_TBL_ENDERECO" ENABLE

CREATE OR REPLACE TRIGGER "BI_TBL_EDITORA"  before insert on "TBL_EDITORA"  for each row  begin  select "TBL_EDITORA_SEQ".nextval into :NEW.COD_EDITORA from dual;
	   	  		  		    end;
							
ALTER TRIGGER "BI_TBL_EDITORA" ENABLE

CREATE OR REPLACE TRIGGER "BI_TBL_AUTOR"  before insert on "TBL_AUTOR"  for each row  begin  select "TBL_AUTOR_SEQ".nextval into :NEW.COD_AUTOR from dual;  
	   	  		  		  end;
						  
ALTER TRIGGER "BI_TBL_AUTOR" ENABLE

